package com.kws.tool.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kws.common.core.domain.R;
import com.kws.common.log.annotation.Log;
import com.kws.common.log.enums.BusinessType;
import com.kws.tool.dto.CreateElectrovalenceRq;
import com.kws.tool.dto.QueryElectrovalenceRq;
import com.kws.tool.dto.UpdateElectrovalenceRq;
import com.kws.tool.entity.TbElectrovalence;
import com.kws.tool.service.ElectrovalenceManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * <b>ElectrovalenceController</b>
 *
 * @description: ElectrovalenceController <br>
 * @date: 2024/11/21 10:23 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Api(tags = "电价管理模块")
@RestController
public class ElectrovalenceController {
    private static final Logger logger = LoggerFactory.getLogger(ElectrovalenceController.class);

    @Autowired
    private ElectrovalenceManagementService electrovalenceManagementService;

    @ApiOperation("分页查询电价维护列表")
    @PostMapping("/query/electrovalencePage")
    public R<Page<TbElectrovalence>> queryElectrovalencePage(@RequestBody QueryElectrovalenceRq rq){
        Page<TbElectrovalence> pageInfo = electrovalenceManagementService.queryElectrovalencePage(rq);
        return R.ok(pageInfo);
    }

    @ApiOperation("新增电价信息")
    @Log(title = "新增电价信息", businessType = BusinessType.INSERT)
    @PostMapping("/create/electrovalence")
    public R createElectrovalence(@RequestBody CreateElectrovalenceRq rq){
        boolean status = electrovalenceManagementService.createElectrovalence(rq);
        return R.ok(status);
    }

    @ApiOperation("根据电价政策ID查询电价政策详情")
    @GetMapping("/query/electrovalence/byId")
    public R<TbElectrovalence> queryElectrovalenceById(@RequestParam Long id){
        TbElectrovalence info = electrovalenceManagementService.queryElectrovalenceById(id);
        return R.ok(info);
    }

    @ApiOperation("修改电价政策信息")
    @Log(title = "修改电价政策信息", businessType = BusinessType.UPDATE)
    @PostMapping("/update/electrovalence")
    public R updateElectrovalence(@RequestBody UpdateElectrovalenceRq rq){
        boolean status = electrovalenceManagementService.updateElectrovalence(rq);
        return R.ok(status);
    }

    @ApiOperation("根据电价政策ID删除电价政策")
    @Log(title = "删除电价政策", businessType = BusinessType.DELETE)
    @GetMapping("/delete/electrovalence/byId")
    public R deleteElectrovalenceById(@RequestParam Long id){
        boolean status = electrovalenceManagementService.deleteElectrovalenceById(id);
        return R.ok(status);
    }

    @ApiOperation("批量上传电价")
    @PostMapping("/upload/electrovalence")
    public R uploadElectrovalence(@RequestParam("file") MultipartFile file,@RequestParam String type) throws IOException {
        return electrovalenceManagementService.uploadElectrovalence(file,type);
    }

    @ApiOperation("查询所有用电类型列表")
    @GetMapping("/query/electricityType/list")
    public R queryElectricityTypeList(@RequestParam(required = false) String electricityType){
        return electrovalenceManagementService.queryElectricityTypeList(electricityType);
    }

    @ApiOperation("查询所有电价等级列表")
    @GetMapping("/query/voltageLevel/list")
    public R queryVoltageLevelList(@RequestParam(required = false) String voltageLevel){
        return electrovalenceManagementService.queryVoltageLevelList(voltageLevel);
    }
}
